package com.corechina.apex_osswords.controller;


import com.corechina.apex_osswords.common.Response;
import com.corechina.apex_osswords.common.SysLog;
import com.corechina.apex_osswords.domain.dto.CoreProjectDto;
import com.corechina.apex_osswords.domain.entity.CoreProjectUser;
import com.corechina.apex_osswords.service.ICorePlaceService;
import com.corechina.apex_osswords.service.ICoreProjectService;
import com.corechina.apex_osswords.service.ICoreProjectUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 项目信息表 前端控制器
 * </p>
 *
 * @author cc
 * @since 2022-03-11
 */
@Api(tags = "项目管理")
@RestController
@RequestMapping("/core/project")
public class CoreProjectController {

    @Autowired
    private ICoreProjectService iCoreProjectService;

    @Autowired
    private ICoreProjectUserService iCoreProjectUserService;

    @Autowired
    private ICorePlaceService iCorePlaceService;

    @ApiOperation("新增")
    @SysLog("新增项目")
    @PostMapping("/add")
    public Response add(@RequestBody CoreProjectDto coreProjectDto) {
        return iCoreProjectService.add(coreProjectDto);
    }

    @ApiOperation("编辑")
    @SysLog("编辑项目")
    @PutMapping("/update")
    public Response update(@RequestBody CoreProjectDto coreProjectDto) {
        return iCoreProjectService.update(coreProjectDto);
    }

    @ApiOperation("删除")
    @SysLog("删除项目")
    @DeleteMapping("/del")
    public Response del(Integer id) {
        return iCoreProjectService.delete(id);
    }

    @ApiOperation("删除项目相关人员")
    @SysLog("删除项目相关人员")
    @DeleteMapping("/delUserForProject")
    public Response delUserForProject(Integer id) {
        iCoreProjectUserService.removeById(id);
        return Response.ok();
    }

    @ApiOperation("新增项目相关人员")
    @SysLog("新增项目相关人员")
    @PutMapping("/addUserForProject")
    public Response addUserForProject(@RequestBody CoreProjectUser coreProjectUser) {
        iCoreProjectUserService.save(coreProjectUser);
        return Response.ok();
    }

    @ApiOperation("获取详情")
    @GetMapping("/getOne")
    public Response getOne(Integer id) {
        return iCoreProjectService.getOne(id);
    }

    @ApiOperation("获取列表")
    @GetMapping("/getList")
    public Response getList(Integer projectType, Integer serviceId, String projectName, String serviceBeginDate, String serviceEndDate, Integer pageIndex, Integer pageSize) {
        return iCoreProjectService.getList(projectType, serviceId, projectName, serviceBeginDate, serviceEndDate, pageIndex, pageSize);
    }

    @ApiOperation("获取项目相关人员列表")
    @GetMapping("/getProjectPersonnelList")
    public Response getProjectPersonnelList(Integer projectId, String name, String company, Integer engineerType, Integer pageIndex, Integer pageSize) {
        return iCoreProjectUserService.getProjectPersonnelList(0, projectId, name, company, engineerType, pageIndex, pageSize);
    }

    @ApiOperation("获取项目地址列表")
    @GetMapping("/getPlaceList")
    public Response getPlaceList(Integer isDel, Integer projectId, Integer pageIndex, Integer pageSize) {
        return iCorePlaceService.getPlaceList(isDel, projectId, pageIndex, pageSize);
    }
}

